@use "Content/scss/sizes";
@use "Content/scss/colors";

//RADIO TOGGLE STYLES

@use "sass:math";

$toggle-label-fontsize: 0.9em !default;

$toggle-baseheight: 40px !default;
$toggle-bg: colors.$well-bg-var !default;
$toggle-color: colors.$text-color-var !default;
$toggle-hover-color: colors.$text-emphasis-var !default;
$toggle-icon-size: 18px !default;
$toggle-width-scale: 2.1 !default;

$toggle-label-highlight-color: colors.$primary-var !default;
$toggle-knob-highlight-color: colors.$base-text-emphasis-color !default;
$toggle-knob-muted-color: colors.$text-muted-var !default;

$toggle-knob-bg: colors.$primary-var !default;
$toggle-knob-scale: 0.8 !default;

$toggle-knob-hover-bg: colors.$primary-var !default;
$toggle-knob-hover-scale: 0.9 !default;

.radio-toggle {
    display: inline-grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    position: relative;
    color: $toggle-knob-muted-color;
    font-weight: bolder;

    input:disabled {
        opacity: 0 !important;
    }

    .toggle-knob {
        align-self: center;
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: relative;
        cursor: pointer;
        flex-shrink: 0;
        order: 2;

        background: $toggle-bg;
        border-radius: $toggle-baseheight;
        height: $toggle-baseheight;
        width: $toggle-baseheight * $toggle-width-scale;
        border: sizes.$border-width solid colors.$border-color-light-var;

        i {
            position: relative;
            z-index: 1;
            height: $toggle-baseheight;
            width: $toggle-baseheight;
            font-size: $toggle-icon-size;
            text-align: center;
            transition: color 0.2s;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        &::after {
            content: "";
            position: absolute;
            background-color: $toggle-knob-bg;
            width: $toggle-baseheight;
            height: $toggle-baseheight;
            border-radius: $toggle-baseheight;
            transform: scale($toggle-knob-scale);
            left: 0;
            transition: 0.2s all sizes.$global-easing-in-out;
        }
    }

    label {
        height: $toggle-baseheight;
        line-height: 1em;
        display: flex;
        align-items: center;
        color: $toggle-knob-muted-color;
        cursor: pointer;
        font-size: $toggle-label-fontsize;
        margin: 0;
        text-align: center;

        &:hover {
            color: $toggle-hover-color;
        }

        &:first-of-type {
            order: 0;
            justify-content: flex-end;
            padding-right: sizes.$gutter-sm;
        }

        &:last-of-type {
            order: 3;
            padding-left: sizes.$gutter-sm;
        }
    }

    input {
        position: absolute;
        opacity: 0;
        height: $toggle-baseheight;
        width: $toggle-baseheight * $toggle-width-scale;
        padding: 0;
        z-index: 2;
        margin: 0;
        display: block;
        left: 50%;
        transform: translateX(-50%);
        cursor: pointer;

        //hover on toggle input
        &:hover ~ .toggle-knob::after {
            transform: scale($toggle-knob-hover-scale);
            background-color: $toggle-knob-hover-bg;
        }

        &:checked {
            z-index: 1; // move the active input to bottom
            pointer-events: none;

            & + label {
                color: $toggle-label-highlight-color;
            }
        }

        &:first-of-type {
            //First radio is active
            &:checked {
                & ~ .toggle-knob {
                    i {
                        &:first-of-type {
                            color: $toggle-knob-highlight-color;
                        }

                        &:last-of-type {
                            color: $toggle-knob-muted-color;
                        }
                    }
                }
            }
        }

        &:last-of-type {
            //Second radio is active
            &:checked {
                & ~ .toggle-knob {
                    i {
                        &:first-of-type {
                            color: $toggle-knob-muted-color;
                        }

                        &:last-of-type {
                            color: $toggle-knob-highlight-color;
                        }
                    }

                    &:after {
                        left: 100% - math.div(100%, $toggle-width-scale);
                    }
                }
            }
        }
    }
}

//RADIO MULTI TOGGLE STYLES

$multi-toggle-label-fontsize: 0.75em !default;

$multi-toggle-baseheight: $toggle-baseheight !default;

$multi-toggle-border-radius: $toggle-baseheight * 0.5 !default;
$multi-toggle-bg: $toggle-bg !default;
$multi-toggle-color: $toggle-color !default;
$multi-toggle-hover-color: $toggle-hover-color !default;

$multi-toggle-knob-highlight-color: var(--bs-white) !default;
$multi-toggle-knob-muted-color: $toggle-knob-muted-color !default;

$multi-toggle-knob-bg: $toggle-knob-bg !default;
$multi-toggle-knob-muted-bg: colors.$panel-header-bg !default;
$multi-toggle-knob-scale: $toggle-knob-scale !default;

$multi-toggle-knob-hover-bg: $toggle-knob-hover-bg !default;

$separator-margin: 3px;
$separator-color: colors.$border-color-light-var;

.multi-toggle {
    .multi-toggle-button {
        border-radius: $multi-toggle-baseheight sizes.$border-radius-sm sizes.$border-radius-sm $multi-toggle-baseheight;
        background-color: transparent;
        border: none;
        font-size: $multi-toggle-label-fontsize;
        padding-left: sizes.$gutter-xs;
        padding-right: sizes.$gutter-xxs;
        box-shadow: none;

        .label-span {
            position: relative;
            display: inline-block;
            .label-clear,
            .label-select-all {
                transition: 0.35s sizes.$easing-rubber;
                pointer-events: none;
            }

            .label-clear {
                opacity: 0;
                position: absolute;
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                left: 0;
                top: 0;
                transform: translateY(1em);
            }
        }

        &.clear-selected {
            .label-select-all {
                opacity: 0;
                transform: translateY(-1em);
            }
            .label-clear {
                opacity: 1;
                transform: translateY(0);
            }
        }
    }

    .multi-toggle-item-count {
        margin-left: sizes.$gutter-xxs;
        background-color: colors.$panel-bg-2-var;
        color: colors.$text-color-var;
        border-radius: sizes.$border-radius-lg;
        padding: 0 sizes.$gutter-xxs;
    }

    .multi-toggle-list {
        background: $multi-toggle-bg;
        border-radius: $multi-toggle-border-radius;
        border: sizes.$border-width solid $separator-color;
        display: inline-flex;
        min-height: $multi-toggle-baseheight;
        color: $multi-toggle-knob-muted-color;
        font-weight: 700;
        flex-wrap: wrap;
        gap: 4px;
        padding: 4px;

        .vr {
            margin: $separator-margin 4px $separator-margin 0;
            background-color: colors.$border-color-var;
            width: 2px;
            opacity: 0.5;
        }

        .multi-toggle-item {
            display: flex;
            position: relative;

            label {
                display: flex;
                align-items: center;
                color: $multi-toggle-knob-muted-color;
                font-size: $multi-toggle-label-fontsize;
                letter-spacing: 0.07em;
                line-height: 1.1rem;
                padding: 4px sizes.$gutter-xs;
                position: relative;
                transition: all 0.6s sizes.$global-easing;
                white-space: nowrap;

                span {
                    position: relative;
                    z-index: 1;
                }

                &::after {
                    content: "";
                    position: absolute;
                    width: 100%;
                    height: 100%;
                    border-radius: $multi-toggle-border-radius;
                    background-color: $multi-toggle-knob-bg;
                    top: 0;
                    left: 0;
                    z-index: 0;
                    opacity: 0;
                    transform: scale($multi-toggle-knob-scale);
                    transition: all 0.1s sizes.$global-easing;
                }
            }

            input[type="radio"],
            input[type="checkbox"] {
                opacity: 0;
                position: absolute;
                cursor: pointer;
                z-index: 2;
                width: 100%;
                height: 100%;

                &:hover + label {
                    color: $multi-toggle-hover-color !important;

                    &:after {
                        opacity: 1;
                        background-color: $multi-toggle-knob-hover-bg !important;
                        transform: scale(1);
                    }
                }

                &:checked {
                    & + label {
                        color: $multi-toggle-knob-highlight-color !important;

                        &:after {
                            opacity: 1;
                            transform: scale(1);
                        }
                    }
                }
            }

            input[type="checkbox"] {
                &:hover + label::after {
                    opacity: 0.75;
                }

                &:checked {
                    & + label {
                        &:after {
                            opacity: 1;
                        }
                    }
                }
            }
        }

        &:hover .multi-toggle-item input[type="radio"] + label {
            color: $multi-toggle-color;

            &::after {
                background-color: $multi-toggle-knob-muted-bg;
            }
        }
    }
}
